package middleware

import (
	"gitee.com/eqyun/gosdk/config"
	"gitee.com/eqyun/gosdk/sdk/common/middleware/handler"
	jwt "github.com/appleboy/gin-jwt/v2"
	"time"
)

const USER_TYPE_KEY = "usr_type_key"

// AuthInit jwt验证new
func AuthInit() (*jwt.GinJWTMiddleware, error) {
	//	timeout := time.Hour
	return jwt.New(&jwt.GinJWTMiddleware{
		Realm:           "test zone",
		Key:             []byte(config.JwtConfig.Secret),
		Timeout:         time.Duration(config.JwtConfig.Timeout) * time.Second,
		MaxRefresh:      time.Hour,
		PayloadFunc:     handler.PayloadFunc,
		IdentityHandler: handler.IdentityHandler,
		Authenticator:   handler.Authenticator,
		Authorizator:    handler.Authorizator,
		Unauthorized:    handler.Unauthorized,
		LogoutResponse:  handler.LogoutResponse,
		LoginResponse:   handler.LoginResponse,
		/*LoginResponse: func(c *gin.Context, code int, message string, time time.Time) {

		},*/
		TokenLookup:   "header: Authorization, query: token, cookie: jwt",
		TokenHeadName: "Bearer",
		TimeFunc:      time.Now,
	})

}
